var express = require('express');
var router = express.Router();
var sql=require('./../sql')
var Banner=require('./../sql/col/banners')


/**
 * @api {get} api/banner 获取轮播图数据
 * @apiDescription 获取轮播图数据，可传递不同的参数以获取数据
 * @apiName banner
 * @apiSuccessExample { json } Success-Response:
 * {
 *  code: '200',
 *  message: '获取轮播图数据',
 *  data: []
 * }
 * {
 *  code: '100',
 *  message: '获取失败',
 *  err:err
 * }
 * @apiSampleRequest /api/banner
 * @apiGroup banner
 * @apiVersion 1.1.0
 **/
router.get('/', function(req, res, next) {
  sql.find(Banner,{},{_id:0}).then(data=>{
    res.send({
      code: '200',
      message: '获取轮播图数据',
      data:data
    });
  }).catch((err)=>{
    res.send({
      code: '100',
      message: '获取失败',
      err:err
    })
  })
});

router.get('/upload', function(req, res, next) {
  const arr=[{ bannerid: 'banner_1', img: 'https://pic.flyco.net.cn/mall/cms/promotion/20200323/20200315.jpg', alt: '' }, 
  { bannerid: 'banner_2', img: 'https://pic.flyco.net.cn/mall/cms/home/swipeBanner/FC5808_wap.jpg', alt: '' }, 
  { bannerid: 'banner_3', img: 'https://pic.flyco.net.cn/mall/cms/home/swipeBanner/FP9001_wap.jpg', alt: '' }, 
  { bannerid: 'banner_4', img: 'https://pic.flyco.net.cn/mall/cms/home/swipeBanner/FH6855-6856-6875-6878.jpg?q=2', alt: '' },
  { bannerid: 'banner_5', img: 'https://pic.flyco.net.cn/mall/cms/home/swipeBanner/FR5255-5256.jpg', alt: '' }];
  sql.insert(Banner,arr).then(()=>{
     res.send('上传成功');       
  })
  .catch(()=>{
    res.send('上传失败');
  })
});


module.exports = router;